<?php 

namespace app\api\controller;

use support\Request;
use think\facade\Db;
use support\exception\ValidateException;
use app\api\model\Sj as SjModel;
use app\api\model\Jyds as JydsModel;


class Sjcontroller
{ 

   

    public function sjdd($request)
    {



         $rows=Db::connect("jyds")->table("wis_orderdatack a")->field("c.send_line,a.ckbh,sum(a.sp_hjje) as ckprice,a.order_id,c.addtime as ddsj,b.dwmc,c.zflx")->join("wis_order c","c.ddbh=a.order_id","LEFT")->join("wis_member b","b.id=c.member_id","LEFT")->where("send_line<>'' and c.ckprice>0 and c.addtime>='".date("Y-m-d", strtotime("-2 day"))."'")->group("a.ckbh")->select();



         foreach ($rows as $k => $v) {
                 
                 $r=SjModel::table("ddd_jcc_04yfk")->where("ckbh='".trim($v['ckbh'])."'")->find();

               

                 $type=1;

                 if($v['zflx'] == 16){
                      $type=2;
                 }


                 if(!$r){
                     SjModel::table("ddd_jcc_04yfk")->insert(['ckbh'=>$v['ckbh'],'send_line'=>$v['send_line'],'ckprice'=>round($v['ckprice'],2),'ddsj'=>$v['ddsj'],'dwmc'=>$v['dwmc'],'type'=>$type,"dsno"=>$v['order_id']]);
                 }else{
                     SjModel::table("ddd_jcc_04yfk")->where("ckbh='".$v['ckbh']."'")->update(['ckprice'=>round($v['ckprice'],2),"dsno"=>$v['order_id'],'ddsj'=>$v['ddsj']]);
                 }
             
         }

        
          return json(['code'=>'200','msg'=>'success']);
    }


   

    




}

 ?>